/*
单个上传
*/
async function singleUpload(path) {
  var ext = path.split('.').pop();
  var nowtime = new Date().getTime()
  return wx.cloud.uploadFile({
    cloudPath: 'images/' + nowtime + "." + ext,
    filePath: path
  })

}
/*批量上传文件
  bookName  图书名称
  arr  [{src:"",name:""},{path:"",name:""}]
*/
async function multiUpload(arr = []) {
  var arrPromise = [];
  arr.forEach((item, index) => {

    var ext = item.path.split('.').pop();
    var nowtime = new Date().getTime()
    var itemPromise = wx.cloud.uploadFile({
      cloudPath: 'audio/' + nowtime + "-" + index + "." + ext,
      filePath: item.path
    })
    arrPromise.push(itemPromise)
  })

  return Promise.all(arrPromise)
}

export {
  multiUpload, singleUpload
}